package my.senix.classics;

import sun.applet.Main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 输入两个正整数m 和n，求其最大公约数和最小公倍数。
 * <p>
 * Created by lhs on 2018/11/7.
 */
public class CommonMultipyDivision {

    /**
     * 利用辗转相除法求出最大公约数，
     * 再 a*b/最大公约数 得出最小公倍数
     */

    public static void main(String[] args) {

        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {

            String str;
            while (true) {
                str = reader.readLine();

                if (str == null || str.equalsIgnoreCase("-1")) {
                    break;
                }

                String[] splits = str.split("\\s");
                Integer a = Integer.valueOf(splits[0]);
                Integer b = Integer.valueOf(splits[1]);

                int d = a > b ? getCommonDivision(a, b) : getCommonDivision(b, a);

                System.out.println("最大公约数是：" + d + ", 最小公倍数是：" + (a * b / d));

            }


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int getCommonDivision(Integer a, Integer b) {
        if (a % b == 0) {
            return b;
        }

        while (true) {
            if ((a = a % b) == 0) {
                return b;
            }

            if ((b = b % a) == 0) {
                return a;
            }
        }


    }

}
